def convert_by_specified_base(number_str: str, base: int):
    try:
        dec = int(number_str, base)
        return {
            "十进制": str(dec),
            "二进制": bin(dec),
            "八进制": oct(dec),
            "十六进制": hex(dec)
        }
    except ValueError:
        return None


def main():
    while True:
        number_str = input("请输入一个数字（输入 q 退出）：").strip()
        if number_str.lower() == 'q':
            break
        print("请选择你输入的进制：\n1. 二进制\n2. 八进制\n3. 十进制\n4. 十六进制")
        choice = input("请输入 1-4：").strip()
        base_map = {'1': 2, '2': 8, '3': 10, '4': 16}
        base = base_map.get(choice, 10)

        result = convert_by_specified_base(number_str, base)
        if result:
            print("\n转换结果：")
            for k, v in result.items():
                print(f"{k}：{v}")
            print()
        else:
            print("转换失败，请检查输入是否符合该进制规则！\n")


if __name__ == "__main__":
    main()